#!/bin/sh

# Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
# Buddha Framework is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#          http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#
# Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
# Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

# copy from $Tomcat/bin/startup.sh
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
PRGDIR=`dirname "$PRG"`
echo $PRGDIR
#

# 生成so文件包换框架版本, 需要生成软链接指向包含框架版本的so文件
# 例如CenterServer.so.3.1.5, 需要生成主版本的软链接CenterServer.so.3, 及最终的CenterServer.so
# 所以调用sh为 : 1. 将文件复制到生成so文件的目录里(确保sh文件有运行权限) 2. 在当前目录启动终端 3. 输入./so_ln.sh 3.1.5 3
if [ "$#" -eq "2" ]  
then  
  echo "$0 $1 $2" 
  FULLVER="$1"
  SHORTVER="$2"
  echo $FULLVER
  echo $SHORTVER

  FULLVERSO=`ls -l | grep "$FULLVER$" | awk {'print $9'}`
  echo $FULLVERSO

  SO=""
  SHORTSO=""
  for FULLSO in $FULLVERSO
  do
    SO=`echo ${FULLSO%%.$FULLVER}`
    echo $SO
    SHORTSO=$SO.$SHORTVER
    echo $SHORTSO
    ln -s $FULLSO $SHORTSO
    ln -s $SHORTSO $SO
  done
  exit 0  
else
  echo "full version AND major version params missing!"
  exit -1
fi  
